Skip to content

server: scope SCCACHE_BASEDIRS to compiler requests - #2814

Closed
tcashel wants to merge 2 commits into
mozilla:mainfrom
tcashel:codex/request-scoped-basedirs
Closed

tcashel wants to merge 2 commits into
mozilla:mainfrom
tcashel:codex/request-scoped-basedirs

Conversation

@tcashel

@tcashel tcashel commented Aug 18, 2026 •

Copy link
Copy Markdown

One sccache daemon currently captures SCCACHE_BASEDIRS at startup, requiring a restart when another worktree needs a different root. This lets each compile request override the file-configured fallback. An absent value uses the fallback; an empty value disables it; an invalid relative path fails that request. Concurrent requests remain isolated in daemon and client-side modes.

Depends on #2813; the request-only diff excludes that prerequisite. The storage wrapper preserves the current upstream raw-cache read API. Tests cover overrides, fallback, statistics, invalid paths, and concurrent requests in both modes.

Formatting, clippy, and the locked unit/integration suite pass on Apple silicon. CUDA cases skip locally; native Windows and CUDA validation are left to CI.

Fixes #2595. Developed with OpenAI Codex.

@codecov-commenter

codecov-commenter commented Aug 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.32402% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.30%. Comparing base (0f9467c) to head (a528aca).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/server.rs 80.76% 5 Missing ⚠️
tests/sccache_cargo.rs 98.29% 4 Missing ⚠️
src/cache/basedirs.rs 97.16% 3 Missing ⚠️
src/compiler/rust.rs 99.25% 2 Missing ⚠️
src/util.rs 99.37% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2814      +/-   ##
==========================================
+ Coverage   76.32%   77.30%   +0.97%     
==========================================
  Files          72       73       +1     
  Lines       40180    40986     +806     
==========================================
+ Hits        30668    31683    +1015     
+ Misses       9512     9303     -209     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread benches/sccache_bench.rs Outdated
bencher.bench(|| black_box(strip_basedirs(black_box(&output), black_box(&basedirs))));
}

#[divan::bench(args = [0, 1, 8, 32])]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the benchmark in a different pr

@tcashel tcashel Aug 29, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thank you for the comment. PR here for ref: #2838

@tcashel
tcashel marked this pull request as ready for review August 29, 2026 01:17
Comment thread src/cache/basedirs.rs
use crate::config::PreprocessorCacheModeConfig;
use crate::errors::*;

struct BasedirsStorage {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

150 lines of forwarding just to carry a Vec<Vec>, and the day someone adds a method to Storage it will silently bypass this wrapper. could we pass the basedirs next to the storage into generate_hash_key instead?

Comment thread src/commands.rs
&cmd,
Command::StartServer | Command::InternalStartServer | Command::ShowStats(_, _)
) {
Config::load_with_file_basedirs()?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoding the command list here is fragile. if the daemon only uses the file value and client-side gets it from the handshake, is the env branch in config_from_env still used at all?

Comment thread src/compiler/rust.rs
digest.update(replacement);
}

fn encode_rust_value(value: &OsStr) -> &[u8] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this wrapper? as_encoded_bytes() reads fine on its own.

Comment thread src/server.rs
return Ok(self.storage.clone());
};

let basedirs = config::parse_basedirs_env(value)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a relative value here makes handle_compile return Err, so the whole compile dies instead of falling back to the real compiler. what does the user actually see? and please add a test for it, it's in the PR description but not covered.

Comment thread src/util.rs Resolved
@sylvestre

Copy link
Copy Markdown
Collaborator

this patch is a bit too large to my taste, sorry

@codspeed

codspeed Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 10.82%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 56 untouched benchmarks
⏩ 6 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation time_macro_finder_chunked 862.8 µs 1,026.4 µs -15.93%
❌ Simulation time_macro_finder_no_macros 2.9 ms 3 ms -5.39%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing tcashel:codex/request-scoped-basedirs (a528aca) with main (0f9467c)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@sylvestre

Copy link
Copy Markdown
Collaborator

hi, this one can't be merged as it is:

  • it needs a rebase
  • the 5 comments above are still open
  • src/config.rs: SCCACHE_BASEDIRS is now parsed twice: here on bytes, and in config_from_env with to_string_lossy (which mangles non-utf8 paths). please dedup on this one.
    could you please have a look? otherwise, i will close it, thanks

blaise-pov added a commit to blaise-pov/sccache that referenced this pull request Oct 21, 2026
@loganrosen

Copy link
Copy Markdown
Contributor

Heads up from the Firefox side: with basedirs covering two checkouts, preprocessor cache mode can already return an object compiled against the other checkout's headers (#2863). I reproduced it on 0.18.0 by building checkout A, stopping the server, then building checkout B with a header changed.

Right now that's partly limited because the server's startup basedirs win. Per-request basedirs would make it easier to hit, so it'd be good if this didn't land before a fix like #2868. In the meantime we're turning off Firefox's default SCCACHE_BASEDIRS for local builds (https://bugzilla.mozilla.org/show_bug.cgi?id=2086340).

@fbartho

fbartho commented Nov 4, 2026

Copy link
Copy Markdown

@tcashel, I rebased this onto main in #2981, keeping your commit and authorship. Thank you for the wave 1!

@sylvestre

Copy link
Copy Markdown
Collaborator

no news since my last ping, closing. reopen whenever you want to continue, thanks

@sylvestre sylvestre closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCCACHE_BASEDIRS support for Worktree workflow

5 participants